package org.szgb.console.ht.electricity.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.szgb.console.utils.PageDto;
import org.szgb.core.base.entity.BeanEntity;

import java.io.Serial;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class HtElectricitySettlementBillItem extends BeanEntity<HtElectricitySettlementBillItem> {
    @Serial
    private static final long serialVersionUID = 1L;
    private HtElectricitySettlementBill htElectricitySettlementBill;
    private HtElectricitySettlementBillItemModel htElectricitySettlementBillItemModel;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate settlementStartDate;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate settlementEndDate;
    private BigDecimal meterReadingStart;
    private BigDecimal meterReadingEnd;
    private BigDecimal settlementUsageKwh;
    private BigDecimal settlementAmountElectricity;
    private BigDecimal gridLineLossFee;
    private BigDecimal comprehensiveErrorCorrectionFee;
    private BigDecimal totalSettlementAmount;
    private String remark;

    public HtElectricitySettlementBillItem() {
    }

    public HtElectricitySettlementBillItem(String id) {
        this.setId(id);
    }


    public HtElectricitySettlementBillItem(HtElectricitySettlementBillItem.HtElectricitySettlementBillItemFindDto htElectricitySettlementBillItemFindDto) {
        this.setId(htElectricitySettlementBillItemFindDto.getId());
        this.setHtElectricitySettlementBill(new HtElectricitySettlementBill(htElectricitySettlementBillItemFindDto.getHtElectricitySettlementBillId()));
        this.setPageDto(htElectricitySettlementBillItemFindDto.getPageDto());
    }

    public HtElectricitySettlementBillItem(HtElectricitySettlementBillItem.HtElectricitySettlementBillItemSaveDto htElectricitySettlementBillItemSaveDto) {
        this.setId(htElectricitySettlementBillItemSaveDto.id);
        this.setHtElectricitySettlementBill(new HtElectricitySettlementBill(htElectricitySettlementBillItemSaveDto.htElectricitySettlementBillId));
        this.setHtElectricitySettlementBillItemModel(new HtElectricitySettlementBillItemModel(htElectricitySettlementBillItemSaveDto.htElectricitySettlementBillItemModelId));
        this.setSettlementStartDate(htElectricitySettlementBillItemSaveDto.settlementStartDate);
        this.setSettlementEndDate(htElectricitySettlementBillItemSaveDto.settlementEndDate);
        this.setMeterReadingStart(htElectricitySettlementBillItemSaveDto.meterReadingStart);
        this.setMeterReadingEnd(htElectricitySettlementBillItemSaveDto.meterReadingEnd);
        this.setSettlementUsageKwh(htElectricitySettlementBillItemSaveDto.settlementUsageKwh);
        this.setSettlementAmountElectricity(htElectricitySettlementBillItemSaveDto.settlementAmountElectricity);
        this.setGridLineLossFee(htElectricitySettlementBillItemSaveDto.gridLineLoseFee);
        this.setComprehensiveErrorCorrectionFee(htElectricitySettlementBillItemSaveDto.comprehensiveErrorCorrectionFee);
        this.setTotalSettlementAmount(htElectricitySettlementBillItemSaveDto.totalSettlementAmount);
        this.setRemark(htElectricitySettlementBillItemSaveDto.remark);
    }

    public HtElectricitySettlementBillItem.HtElectricitySettlementBillItemView toHtElectricitySettlementBillItemView() {
        return new HtElectricitySettlementBillItem.HtElectricitySettlementBillItemView(this);
    }

    @Data
    @Schema(title = "电量结算单细项信息", description = "电量结算单细项信息")
    public static class HtElectricitySettlementBillItemView {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "电量结算单id")
        private String htElectricitySettlementBillId;
        @Schema(description = "电量结算单细项模板id")
        private String htElectricitySettlementBillItemModelId;
        @Schema(description = "接用类型")
        private String connectionType;
        @Schema(description = "接用地点")
        private String connectionLocation;
        @Schema(description = "排序参数")
        private Integer sortOrder;
        @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @Schema(description = "结算开始时间")
        private LocalDate settlementStartDate;
        @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @Schema(description = "结算结束时间")
        private LocalDate settlementEndDate;
        @Schema(description = "表计开始读数(kwh)")
        private BigDecimal meterReadingStart;
        @Schema(description = "表计结束读数(kwh)")
        private BigDecimal meterReadingEnd;
        @Schema(description = "用电结算用量(kwh)")
        private BigDecimal settlementUsageKwh;
        @Schema(description = "用电量结算费用(￥)")
        private BigDecimal settlementAmountElectricity;
        @Schema(description = "电网线损费用(￥)")
        private BigDecimal gridLineLoseFee;
        @Schema(description = "综合误差修正费用(￥)")
        private BigDecimal comprehensiveErrorCorrectionFee;
        @Schema(description = "结算金额(￥)")
        private BigDecimal totalSettlementAmount;
        @Schema(description = "备注")
        private String remark;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "创建时间")
        private LocalDateTime createdAt;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "更新时间")
        private LocalDateTime updatedAt;
        @Schema(description = "创建人id")
        private String createdById;
        @Schema(description = "创建人姓名")
        private String createdByName;
        @Schema(description = "更新人id")
        private String updatedById;
        @Schema(description = "更新人姓名")
        private String updatedByName;

        public HtElectricitySettlementBillItemView(HtElectricitySettlementBillItem htElectricitySettlementBillItem) {
            this.id = htElectricitySettlementBillItem.getId();
            this.htElectricitySettlementBillId = htElectricitySettlementBillItem.getHtElectricitySettlementBill().getId();
            this.htElectricitySettlementBillItemModelId = htElectricitySettlementBillItem.getHtElectricitySettlementBillItemModel().getId();
            this.connectionType = htElectricitySettlementBillItem.getHtElectricitySettlementBillItemModel().getConnectionType();
            this.connectionLocation = htElectricitySettlementBillItem.getHtElectricitySettlementBillItemModel().getConnectionLocation();
            this.sortOrder = htElectricitySettlementBillItem.getHtElectricitySettlementBillItemModel().getSortOrder();
            this.settlementStartDate = htElectricitySettlementBillItem.getSettlementStartDate();
            this.settlementEndDate = htElectricitySettlementBillItem.getSettlementEndDate();
            this.meterReadingStart = htElectricitySettlementBillItem.getMeterReadingStart();
            this.meterReadingEnd = htElectricitySettlementBillItem.getMeterReadingEnd();
            this.settlementUsageKwh = htElectricitySettlementBillItem.getSettlementUsageKwh();
            this.settlementAmountElectricity = htElectricitySettlementBillItem.getSettlementAmountElectricity();
            this.gridLineLoseFee = htElectricitySettlementBillItem.getGridLineLossFee();
            this.comprehensiveErrorCorrectionFee = htElectricitySettlementBillItem.getComprehensiveErrorCorrectionFee();
            this.totalSettlementAmount = htElectricitySettlementBillItem.getTotalSettlementAmount();
            this.remark = htElectricitySettlementBillItem.getRemark();
            this.createdAt = htElectricitySettlementBillItem.getCreatedAt();
            this.updatedAt = htElectricitySettlementBillItem.getUpdatedAt();
            if (htElectricitySettlementBillItem.getCreatedBy() != null) {
                this.createdById = htElectricitySettlementBillItem.getCreatedBy().getId();
                this.createdByName = htElectricitySettlementBillItem.getCreatedBy().getName();
            }
            if (htElectricitySettlementBillItem.getUpdatedBy() != null) {
                this.updatedById = htElectricitySettlementBillItem.getUpdatedBy().getId();
                this.updatedByName = htElectricitySettlementBillItem.getUpdatedBy().getName();
            }
        }

        public static List<HtElectricitySettlementBillItem.HtElectricitySettlementBillItemView> getViewListFromList(List<HtElectricitySettlementBillItem> htElectricitySettlementBillItemList) {
            return htElectricitySettlementBillItemList.stream().map(HtElectricitySettlementBillItem.HtElectricitySettlementBillItemView::new).toList();
        }
    }

    @Data
    @Schema(title = "电量结算单细项查询表单", description = "电量结算单细项查询参数")
    public static class HtElectricitySettlementBillItemFindDto {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "电量结算单id")
        private String htElectricitySettlementBillId;
        @Schema(description = "分页信息")
        private PageDto pageDto;

        public HtElectricitySettlementBillItem toHtElectricitySettlementBillItem() {
            return new HtElectricitySettlementBillItem(this);
        }
    }

    @Data
    @Schema(title = "电量结算单细项保存表单", description = "电量结算单细项保存参数")
    public static class HtElectricitySettlementBillItemSaveDto {
        @Schema(description = "id(如为空则为新增数据)")
        private String id;
        @Schema(description = "电量结算单id")
        private String htElectricitySettlementBillId;
        @Schema(description = "电量结算单细项模板id")
        private String htElectricitySettlementBillItemModelId;
        @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @Schema(description = "结算开始时间")
        private LocalDate settlementStartDate;
        @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd")
        @Schema(description = "结算结束时间")
        private LocalDate settlementEndDate;
        @Schema(description = "表计开始读数(kwh)")
        private BigDecimal meterReadingStart;
        @Schema(description = "表计结束读数(kwh)")
        private BigDecimal meterReadingEnd;
        @Schema(description = "用电结算用量(kwh)")
        private BigDecimal settlementUsageKwh;
        @Schema(description = "用电量结算费用(￥)")
        private BigDecimal settlementAmountElectricity;
        @Schema(description = "电网线损费用(￥)")
        private BigDecimal gridLineLoseFee;
        @Schema(description = "综合误差修正费用(￥)")
        private BigDecimal comprehensiveErrorCorrectionFee;
        @Schema(description = "结算金额(￥)")
        private BigDecimal totalSettlementAmount;
        @Schema(description = "备注")
        private String remark;

        public HtElectricitySettlementBillItem toHtElectricitySettlementBillItem() {
            return new HtElectricitySettlementBillItem(this);
        }
    }
}
